// pages/qiandao/qiandaoPage.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    companyLatitude: 32.067390000,//改成家里的坐标
    companyLongitude:118.77013,
    latitude: 32.19136682467052,
    longitude: 120.62778800722539
  },
  qiandao: function () {//签到
    var that=this;
      wx.getLocation({
          success: function (res) {
            var  currentLatitude = res.latitude
            var  currentLongitude = res.longitude
              that.setData({
                  latitude: currentLatitude,
                  longitude: currentLongitude
              })
              that.mapCtx.moveToLocation()
              if (Math.abs(that.data.companyLatitude - currentLatitude) < 0.002 && Math.abs(that.data.companyLongitude - currentLongitude)<0.002){
                  wx.showToast({
                      title: '签到成功',
                      icon: 'success',
                      duration: 2000
                  })
              }else {
                  wx.showToast({
                      title: '不在签到范围内!',
                      icon: 'none',
                      duration: 2000
                  })
              }

          }
      })
  },
  qiantui: function () {//签退
    var that = this;
    wx.getLocation({
      success: function (res) {
        var currentLatitude = res.latitude
        var currentLongitude = res.longitude
        that.setData({
          latitude: currentLatitude,
          longitude: currentLongitude
        })
        that.mapCtx.moveToLocation()
        if (Math.abs(that.data.companyLatitude - currentLatitude) < 0.002 && Math.abs(that.data.companyLongitude - currentLongitude) < 0.002) {
          wx.showToast({
            title: '签退成功',
            icon: 'success',
            duration: 2000
          })
        } else {
          wx.showToast({
            title: '不在签退范围内!',
            icon: 'none',
            duration: 2000
          })
        }

      }
    })
  },





  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      wx.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: '#1aad19',
          animation: {
              duration: 400,
              timingFunc: 'easeIn'
          }
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.mapCtx = wx.createMapContext('myMap')
    this.mapCtx.moveToLocation()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})